package edu.sygyzy.service;

import edu.sygyzy.entity.Employee;
import edu.sygyzy.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    public List<Employee> findAll() {
        return employeeMapper.findAll();
    }

    public void save(Employee employee) {
        if (employee.getId() == null) {
            employeeMapper.insert(employee);
        } else {
            employeeMapper.update(employee);
        }
    }

    public void update(Employee employee){
        if(employee.getId()!=null){
            employeeMapper.update(employee);
        }
    }

    public void delete(Integer id) {
        employeeMapper.delete(id);
    }
}
